package com.learn.springcloud.hystrixexplaininattributeconsumer.command.service;

import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandProperties;
import org.springframework.web.client.RestTemplate;

/**
 * 继承方式配置隔离策略
 *
 * @Time : 2018/8/7 11:56
 * @Version : 1.0
 */
public class CommandExecutionIsolationStrategyExtrend extends HystrixCommand<String> {

    private RestTemplate restTemplate;
    private String name;

    protected CommandExecutionIsolationStrategyExtrend(RestTemplate restTemplate, String name) {
        super(
            Setter
                .withGroupKey(
                        HystrixCommandGroupKey.Factory.asKey("aaa")
                )
                .andCommandPropertiesDefaults(
                        HystrixCommandProperties.Setter().withExecutionTimeoutInMilliseconds(500)
                )
                .andCommandPropertiesDefaults(
                        HystrixCommandProperties.Setter().withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE)
                )
        );
        this.restTemplate = restTemplate;
        this.name = name;
    }

    @Override
    protected String run() throws Exception {
        return null;
    }
}
